package connection;

import java.io.DataInputStream;
import java.io.IOException;
import java.net.Socket;

public abstract class ConnectionIn implements Runnable {
	private Socket socket;
	protected DataInputStream dis;
	protected Relay relay;
	
	public ConnectionIn(Socket socket, Relay relay) {
		this.socket = socket;
		this.relay = relay;
	}

	@Override
	public void run() {
		try {
			dis = new DataInputStream(socket.getInputStream());
			while (true) {
				while (!(dis.available() > 2)) {
					Thread.sleep(100);
				}
				handleMessage();
			}
		} 
		catch (IOException e) {
			e.printStackTrace();
		} 
		catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	protected abstract void handleMessage();
}
